﻿using System;
using DomainModel;
using Repository.Abstract;

namespace Repository.NHibernate
{
    public class RingRepository : Repository<Ring>, IRingRepository
    {
        public Ring GetRingByPairNo(int pairNo)
        {
            return Session.QueryOver<Ring>().Where(r => r.PairNo == pairNo).SingleOrDefault();
        }

        public int GetPairNoByTime(DateTime time)
        {
            var pair = Session.QueryOver<Ring>().Where(r => r.BeginTime <= time && r.EndTime >= time).SingleOrDefault();

            if (pair == null)
            {
                return 0;
            }

            return pair.PairNo;
        }
    }
}